﻿@model IEnumerable<BootyBay.Models.View_AppOptRecord4User>
@{
    List<SelectListItem> categoryList = new List<SelectListItem>() {
                new SelectListItem(){ Text = "N/A", Value = ((int)BootyBay.Models.AppOperationType.NA).ToString(), Selected=false },
                new SelectListItem(){ Text = "RequestToInstall", Value = ((int)BootyBay.Models.AppOperationType.RequestToInstall).ToString(), Selected=false },
                new SelectListItem(){ Text = "RequestToUninstall", Value = ((int)BootyBay.Models.AppOperationType.RequestToUninstall).ToString(), Selected=false },
               };
}


<h3>Application for @ViewBag.UserName</h3>

@if (ViewBag.ErrorMessage != null)
{
    <div>
        <p style="color:red">@ViewBag.ErrorMessage</p>
    </div>
}
@if (ViewBag.SuccessMessage != null)
{
    <div>
        <p style="color:green">@ViewBag.SuccessMessage</p>
    </div>
}

<table>
    <tr>
        <th>Alias</th>
        <th>Status</th>
        <th colspan="2">Set Operation</th>
    </tr>
    @if (Model.Count() == 0)
    {
        <tr>
            <td colspan="4">
                No data.
            </td>
        </tr>
    }
    else
    {
        foreach (var item in Model)
        {
            <tr>
                <td> @item.ApplicationName</td>
                <td>@((BootyBay.Models.AppOperationType)item.OperationType)</td>
                <td>
                    @using (Ajax.BeginForm("SetOperation", new { username = ViewBag.UserName, Id_Application = item.Id_Application }, new AjaxOptions() { HttpMethod = "POST", UpdateTargetId = "applicationListContent", InsertionMode = InsertionMode.Replace }, new { id = "SetOperationForm" + item.Id_Application.ToString() }))
                    {
                        <select name="OperationType">
                            <option value="@((int)BootyBay.Models.AppOperationType.NA)" 
                            @(item.OperationType == BootyBay.Models.AppOperationType.NA ? "selected=selected" : "")>N/A</option>
                            <option value="@((int)BootyBay.Models.AppOperationType.RequestToInstall)" 
                            @(item.OperationType == BootyBay.Models.AppOperationType.RequestToInstall ? "selected=selected" : "")>RequestToInstall</option>
                            <option value="@((int)BootyBay.Models.AppOperationType.RequestToUninstall)" 
                            @(item.OperationType == BootyBay.Models.AppOperationType.RequestToUninstall ? "selected=selected" : "")>RequestToUninstall</option>
                        </select>
                    }
                </td>
                <td>
                    <a href="javascript:void(0)" onclick="$('form#SetOperationForm@(item.Id_Application)').trigger('submit');">Set</a>
                </td>
            </tr>
        }
    }
</table>